<!DOCTYPE html>
<html lang="en">
	<head>
	
    <title>CBE BPE Toolkit - Building Scorecard Setup</title>

    <link href="/static/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/anytime/css/anytimec.css"/>
    <link rel="stylesheet" type="text/css" href="/static/pmp/css/plot.css"/>
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
      .sidebar-nav {
        padding: 9px 0;
      }
    </style>
    <script type="text/javascript" src="/static/jquery-1.7.2/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="/static/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/static/sessvars/sessvars.js"></script>
    <script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js"></script>
  </head>

  <body>
	{% include 'header.html' %}
        <div class="span10" id="mainContent">
        	<h4>Survey results</h4>
        	<p style="font-size: 11px">Enter the results of the CBE IEQ survey into the relevant fields</p>
			<hr>
			<div id='surveyInline'></div>
			
        	<h4>Model Definition</h4>
        	<p style="font-size: 11px">Setup the assessment conditions for each IEQ category</p>
			<hr>
        	<form id='ieqModelForm' class="form-inline">
				<label class="control-label">IEQ Model: &nbsp;</label>
				{{ ieq_model.management_form }}
				{{ ieq_model.name }}&nbsp;<a href="grid" class="add-another" id="add_id_model" onclick="return addModel(this);"><img src="/static/admin/img/icon_addlink.gif" width="10" height="10" alt="Add Another"/></a>
			</form>
			<div id='setupInline'></div>
		</div>
		</div>
      <hr>
		{% include 'footer.html' %}
    </div><!--/.fluid-container-->

</body>
<script>
	$(document).ready(function(){
		$("li#" + window.location.pathname.substring(5, window.location.pathname.length - 1)).addClass("active") 
	    $('select#id_name').change(function() { 
    		var projectId = $(this).val();
    		sessvars.sessionObj={'projectId': projectId}
    		readSurvey();
    	})
    	$('select#id_ieqModel_name').change(function() {
    		modelId = $(this).val();
			$.ajax({
				type: "POST",
				url: '/pmp/scsetup/',
				data: {'modelId': modelId, 'select':'changeModel'},
				success: function(data){
					$('#setupInline').html(data)        
				}
			});
    	})
    	readSurvey();
	})
	function readSurvey(){
		var projectId = sessvars.sessionObj['projectId']
		$.ajax({
			type: "POST",
			url: '/pmp/scsetup/',
			data: JSON.stringify({'select': 'readSurvey','projectId':projectId}),
			success: function(data){
				$('#surveyInline').html(data)
				$('#surveysuccess').fadeIn().delay(2000).fadeOut(1000);    
			}
		});
	}
	function addModel(name){
		var projectId = sessvars.sessionObj['projectId']
		var win = window.open('/pmp/utils?utilType=addModel', name, 'height=500,width=400,resizable=yes,scrollbars=yes');
		win.focus();       
		return false;
	}
	if (typeof sessvars.sessionObj == 'undefined'){sessvars.sessionObj = {'projectId': $('select#id_name').find("option:selected").val()};}
	if (typeof sessvars.sessionObj != 'undefined'){
		if (sessvars.sessionObj['projectId'] == ""){sessvars.sessionObj['projectId'] = $('select#id_name').find("option:selected").val();}
		else {
			for (var i=0;i<document.getElementById('id_name').options.length;i++) {
				if (document.getElementById('id_name').options[i].value == sessvars.sessionObj['projectId'])
					{document.getElementById('id_name').options[i].selected = true;}
			}
		}
	}
	$.fn.serializeObject = function() {
	  var arrayData, objectData;
	  arrayData = this.serializeArray();
	  objectData = {};
	
	  $.each(arrayData, function() {
	    var value;
	
	    if (this.value != null) {
	      value = this.value;
	    } else {
	      value = '';
	    }
	
	    if (objectData[this.name] != null) {
	      if (!objectData[this.name].push) {
	        objectData[this.name] = [objectData[this.name]];
	      }
	
	      objectData[this.name].push(value);
	    } else {
	      objectData[this.name] = value;
	    }
	  });
	
	  return objectData;
	};
</script>
</html>